//
//  EmptyView.m
//  Project_IOS
//
//  Created by topnet on 2022/4/13.
//

#import "EmptyView.h"

@implementation EmptyView

- (instancetype)init {
    if (self = [super init]) {
        [self addSubview:self.iv];
        [self addSubview:self.lbl];
    }
    return self;
}

- (void)loading {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.superview bringSubviewToFront:self];
        self.hidden = NO;
//        [self.iv sd_setImageWithURL:[NSURL fileURLWithPath:[NSBundle.mainBundle pathForResource:@"search_image" ofType:@"png"]]];
        self.lbl.text = @"";
    });
}

- (void)loadEmpty {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.superview bringSubviewToFront:self];
        self.hidden = NO;
        self.iv.image = [UIImage imageNamed:@"zq_empty"];
        self.lbl.text = @"暂无内容";
    });
}

- (void)loadNetError {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.superview bringSubviewToFront:self];
        self.hidden = NO;
        self.iv.image = [UIImage imageNamed:@"zq_net_error"];
        self.lbl.text = @"网络错误，请稍后重试";
    });
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat _size = self.bounds.size.width * 0.65;
    
    self.iv.frame = CGRectMake((self.bounds.size.width - _size)/2, self.bounds.size.height * 0.2, _size, _size);
    self.lbl.frame = CGRectMake(self.iv.frame.origin.x, CGRectGetMaxY(self.iv.frame) + 10, _size, 25);
    
//    [self.iv mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(@0);
//        make.width.height.equalTo(self.mas_width).multipliedBy(0.65);
//        make.top.equalTo(self.mas_height).multipliedBy(0.2);
//    }];
//    [self.lbl mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.equalTo(self.iv);
//        make.top.equalTo(self.iv.mas_bottom).offset(10));
//        make.height.mas_equalTo(25);
//    }];
}

- (UILabel *)lbl {
    if (!_lbl) {
        _lbl = [UILabel new];
        _lbl.font = [UIFont systemFontOfSize:15];
        _lbl.textAlignment = NSTextAlignmentCenter;
        _lbl.textColor = UIColor.lightGrayColor;
    }
    return _lbl;
}

- (UIImageView *)iv {
    if (!_iv) {
        _iv = [UIImageView new];
    }
    return _iv;
}

@end
